package main

import "fmt"

func sumFn(x int, y int) int {
	sum := x + y
	return sum
}

// 参数简写
func sumFn2(x, y int) int {
	sum := x + y
	return sum
}

// 可变参数
func sumFn3(x ...int) {
	fmt.Printf("%v--%T\n", x, x)
}

// 返回多个值
func calc(x, y int) (int, int) {
	return x + y, x - y
}

// 命名返回值
func calc2(x, y int) (sum int, diff int) {
	sum = x + y
	diff = x - y
	return
}

// 闭包
func adder() func() int {
	var i = 10
	return func() int {
		return i + 1
	}
}

func swap(x, y *int) {
	*x, *y = *y, *x
}

func main() {
	// sumFn3(1, 2, 3, 4, 5)
	a, _ := calc(10, 5)
	fmt.Println(a)
	func() {
		fmt.Println("匿名函数")
	}()
	fmt.Println(adder()())
	fmt.Println(adder()())
	c := 10
	d := 20
	swap(&c, &d)
	fmt.Println("c:", c, "d:", d)
	ic := &c
	icc := &ic
	fmt.Println(**icc)
}
